var args = process.argv.slice(2);
const svg = args[0];
console.log(`input from svg file: ${svg}`)
var xml2js = require('xml2js');
var fs = require('fs');
var path = require('path');
 
var xmlParser = new xml2js.Parser({explicitArray: false, ignoreAttrs: false}); // xml -> json

fs.readFile(svg,'utf-8',function(err,result){
    var obj = {};
    xmlParser.parseString(result, function (err, result) {
        var glyphs = result.svg.defs.font.glyph;
        glyphs.forEach((glyph) => {
            var name = glyph.$["glyph-name"];
            var value = glyph.$["unicode"];
            obj[name] = value.charCodeAt(0);
        }); 
    });
    var dir = path.dirname(svg);
    var name = path.basename(svg,"svg");
    var output = path.join(dir,name+"json");
    console.log(`output to json file: ${output}`)
    fs.writeFileSync(output,JSON.stringify(obj));
});